package com.ymatou.iapi.sellerquery.service;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ymatou.query.seller.trading.api.parameter.ExportSellerProductInfosResponse;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;

/**
 * @date 2016-06-28
 * @desc 分批导出卖家商品信息
 * 
 * @author songyefeng
 *
 */
public class ExportSellerProductInfosCall extends YmatouBaseCall {
	private static String opurl = "api/Seller/ExportSellerProductInfos";

	public ExportSellerProductInfosCall() {
		super(EnvSetup.getSystemUrl("sellerquery_iapi"), opurl, "POST",
				"JSON");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept",
				"text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取Code
	 * 
	 * @return
	 */
	public String getCode() {
		String Code = null;
		try {
			Code = new JSONObject(getReturnData()).getString("code");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取BCode
	 * 
	 * @return
	 */
	public String getBCode() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("bcode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Msg
	 * 
	 * @return
	 */
	public String getMsg() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("msg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Data
	 * 
	 * @return
	 */
	public Object getData() {
		Object Data = null;
		try {
			Data = new JSONObject(getReturnData()).get("data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}

	public ExportSellerProductInfosResponse getExportSellerProductInfosResponse() {
		ExportSellerProductInfosResponse response = null;
		try {
			response = (ExportSellerProductInfosResponse) FormatUtil
					.GSONToObject(DataUtil.Json.parseJsonObj(getData().toString()).toString(), ExportSellerProductInfosResponse.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return response;
	}

	/**
	 * 获取Data.SellerExportedPartialProductInfos
	 * 
	 * @return
	 */
	public JSONArray getSellerExportedPartialProductInfos() {
		JSONArray sellerExportedPartialOrderInfos = null;
		try {
			sellerExportedPartialOrderInfos = ((JSONObject) getData())
					.getJSONArray("SellerExportedPartialProductInfos");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return sellerExportedPartialOrderInfos;
	}

	/**
	 * 获取NextPartitionKey
	 * 
	 * @return
	 */
	public String getNextPartitionKey() {
		String nextPartitionKey = null;
		try {
			nextPartitionKey = ((JSONObject) getData())
					.getString("NextPartitionKey");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return nextPartitionKey;
	}

}
